//
//  ZYImageViewCell.m
//  Project_B
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 ZY. All rights reserved.
//

#import "ZYImageViewCell.h"

@interface ZYImageViewCell ()

@property(nonatomic,strong)UIImageView *leftImgView;
@property(nonatomic,strong)UIImageView *middleImgView;
@property(nonatomic,strong)UIImageView *rightImgView;
@property(nonatomic,strong)UILabel *titleLb;
@property(nonatomic,strong)UILabel *replyLb;
@end
@implementation ZYImageViewCell

#pragma mark -
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}


#pragma mark -
-(void)createSubView{
    
    
    //标题
    self.titleLb = [[UILabel alloc]init];
//    self.titleLb.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.titleLb];
    //文字左对齐
    self.titleLb.textAlignment = NSTextAlignmentLeft;
    self.titleLb.font = [UIFont boldSystemFontOfSize:15*ADAPT_FONT];
    self.titleLb.textColor = [UIColor colorWithHue:0.67 saturation:0.01 brightness:0.33 alpha:1];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        
        
        make.left.and.top.mas_equalTo(SPACE);
        make.width.mas_equalTo(SCREEN_WIDTH - SPACE*2.5 - IMG_HEIGHT/4*3);
        make.height.mas_equalTo(SPACE*1.5);
        
    }];

    
    //跟帖数
    _replyLb = [[UILabel alloc]init];
//    _replyLb.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_replyLb];
    _replyLb.textAlignment = NSTextAlignmentRight;
    _replyLb.font = [UIFont systemFontOfSize:13*ADAPT_FONT];
    _replyLb.textColor = [UIColor colorWithHue:0.58 saturation:0.01 brightness:0.69 alpha:1];

    
    [_replyLb mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.titleLb.mas_bottom);
        make.right.mas_equalTo(-SPACE);
        make.width.mas_equalTo(IMG_HEIGHT/4*3);
        make.height.mas_equalTo(SPACE);
        
    }];
    
    
    
    //左图
    self.leftImgView = [[UIImageView alloc]init];
//    self.leftImgView.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:self.leftImgView];
    self.leftImgView.layer.masksToBounds = YES;
    self.leftImgView.layer.cornerRadius = 3;
    
    [_leftImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.titleLb.mas_left);
        make.top.equalTo(self.titleLb.mas_bottom).offset(SPACE/2);
        make.width.mas_equalTo((SCREEN_WIDTH-SPACE*3)/3);
        make.height.mas_equalTo(IMG_HEIGHT);
        
    }];
    
    
    
    //中图
    self.middleImgView = [[UIImageView alloc]init];
//    self.middleImgView.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.middleImgView];
    self.middleImgView.layer.masksToBounds = YES;
    self.middleImgView.layer.cornerRadius = 3;
    
    
    [_middleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.leftImgView.mas_right).offset(SPACE/2);
        make.top.equalTo(self.leftImgView.mas_top);
        make.size.equalTo(self.leftImgView);
        
    }];

    
    
    
    //右图
    self.rightImgView = [[UIImageView alloc]init];
//    self.rightImgView.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.rightImgView];
    self.rightImgView.layer.masksToBounds = YES;
    self.rightImgView.layer.cornerRadius = 3;
    
    
    [_rightImgView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.middleImgView.mas_right).offset(SPACE/2);
        make.top.equalTo(self.middleImgView.mas_top);
        make.size.equalTo(self.middleImgView);
        
    }];
    
    
    
}



#pragma mark -
-(void)setModel:(NewestModel *)model{
    _model = model;

    self.titleLb.text = model.title;
    self.replyLb.text = [NSString stringWithFormat:@"%@跟帖",model.replyCount];

    [self.leftImgView sd_setImageWithURL:model.imgsrc placeholderImage:PLACEHOLDER_IMAGE];
    
    NSURL *middleUrl = [[model.imgextra objectAtIndex:0]objectForKey:@"imgsrc"];
    [self.middleImgView sd_setImageWithURL:middleUrl placeholderImage:PLACEHOLDER_IMAGE];
    
    NSURL *rightUrl = [[model.imgextra objectAtIndex:1]objectForKey:@"imgsrc"];
    [self.rightImgView sd_setImageWithURL:rightUrl placeholderImage:PLACEHOLDER_IMAGE];
}







#pragma mark -
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
